<?php

require_once './include/common.inc.php';
require_once 'left.php';
require_once 'right.php';
include_once './include/cart.class_p.php';

$page_title = 'Acuity World WebShop';
$menu_id = 0;
$menu_str = PrintMenu();

$cart_list = '';

$transacknum = $_GET['transacknum'];
$orderid = substr($_GET['orderid'],1);//去除订单号的前缀'p'
$actioncode = $_GET['actioncode'];
$promoter_login=true;//used in head.htm

$sql = "select `id` from `promoter_order` WHERE `id` = '$orderid' AND `transacknum`=0 limit 1";
$tmp = $db->get_one($sql);

if (!empty($tmp)) {

    // ĶϢ
    $sql = "update `promoter_order` set `transacknum` = '$transacknum',`pay_flag` = '0' WHERE `id` = '$orderid' limit 1";
    $db->query($sql);


    $sql = "select `promoter_id`, `cost`, `cart_info`, `card_name`, `card_number`, `card_type`, `d_street`, `d_city`, `d_state`, `d_zip`, `d_country` from `promoter_order` WHERE `id` = '$orderid' limit 1";
    $tmp_order_ary = $db->get_one($sql);

    $promoter_id = $tmp_order_ary['promoter_id'];

    // ȡµûϢ
    $sql = "select `email`, `firstname`, `lastname`, `street`, `city`, `state`, `zip`, `country`, `phone`, `mobile` from `promoter_info` WHERE `id` = '$promoter_id' limit 1";
    $user_info_ary = $db->get_one($sql);
	//清空临时订单
	$sql = "update `promoter_order_tmp` set `info` = '' WHERE `promoter_id` = '$promoter_id' limit 1";
    $db->query($sql);

    $cart = new cart();
	
    if (!$cart = unserialize($tmp_order_ary['cart_info'])) {
        $cart = new cart();
    }
	/////update stock_data--------------------------------------leo
	$myCart = $cart->getData();
	$sql_update="";
	foreach($myCart as $key=>$val)
	{
		if($key>0)
		{
			if($val["count"]>0)
			{
				$sql_update="update pro_product set stock_data=stock_data-".$val["count"]." where id=".$key;
				//$mysql->query($sql_update);
			}
		}
	}

	///////////////
	
	$cart_info_ary = $cart->getData();	
	foreach ($cart_info_ary as $k=>$v) 
	{
		$price_show = $v['price'];
		$cart_list .= '<tr>
				<td class="en_black_12">'. $v['name'] .'</td>
				<td class="en_black_12">'. $price_show .'</td>
				<td class="en_black_12">'. $v['count'] .'</td>
				<td class="en_black_12">'. $v['cost'] .'</td>
			  </tr>';
	}
	$totalCost=$cart->getTotalCost();
	$discount=$cart->getDisCount();
	$new_total=number_format($totalCost-$discount,2,'.','');
	$vat_fee=$cart->getAddVat();
	$addshippingfee=$cart->getAddShippingFee();
	$totalCost2=$cart->getTotalCost2();
	
	$cart_list .= '<tr>
					<td class="en_black_12" colspan="4" align="right">
						<strong>Sub Total:</strong> DKK'.$totalCost.'<br/> 
						<strong>Discount:</strong> DKK'.$discount.'<br/>
						<strong>New Sub Total:</strong> DKK'.$new_total.'<br/> 
						<strong>VAT:</strong> DKK'.$vat_fee.'<br/> 
						<strong>Shipping Fee:</strong> DKK'.$addshippingfee.'<br/> 
						<strong>Total:</strong> '.$totalCost2.'</td>				
				  </tr>';
    // ʼ send_email
    $username = empty($user_info_ary['lastname']) ? $user_info_ary['firstname'] : $user_info_ary['firstname'] . ' ' . $user_info_ary['lastname'];
    $email = $user_info_ary['email'];
    $day = date("Y-m-d", $timestamp);
    $deliveryaddress = $tmp_order_ary['d_street'] . "<br>" . $tmp_order_ary['d_city'] . "<br>" . $tmp_order_ary['d_state'] . "<br>" . $tmp_order_ary['d_zip'] . "<br>" . $tmp_order_ary['d_country'];
	$customaddress = $user_info_ary['street'] . "<br>" . $user_info_ary['city'] . "<br>" . $user_info_ary['state'] . "<br>" . $user_info_ary['zip'] . "<br>" . $user_info_ary['country'];
	
    $phone = str_replace("||", " " , $user_info_ary['phone']);
    $mobile = str_replace("||", " " , $user_info_ary['mobile']);
	$tmp_order_ary['card_number']=substr($tmp_order_ary['card_number'], -4); 
	
 	require_once './mail/order_to_promoters2.php';
    sendhtmlmail($from_name,$from_email,$to_name,$to_email,$subject,$content);
		
	require_once './mail/order_promoter_to_webmaster2.php';
    sendhtmlmail($from_name,$from_email,$to_name,$to_email,$subject,$content);
 
}

require_once PrintEot('header');
require_once PrintEot('left');
require_once PrintEot('promoter_payapproved');
require_once PrintEot('right');
require_once PrintEot('footer');
?>
